package com.qianfeng.smartmeeting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianfeng.smartmeeting.entity.UserEntity;
import com.qianfeng.smartmeeting.mapper.UserMapper;
import com.qianfeng.smartmeeting.service.LoginService;
import com.qianfeng.smartmeeting.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements LoginService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserEntity findByUserName(String username) {
        QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", username);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public void register(UserEntity user) {
        user.setUserPassword(Md5Util.getMD5String(user.getUserPassword()));
        user.setUserEnable(1);
        user.setUserType(2);
        this.save(user);
    }
}
